﻿#include "CTagButton.h"
#include <QUuid>
#include <QPainter>

CTagButton::CTagButton(QWidget *parent)
{
	initUI();
	initData();
}

CTagButton::~CTagButton()
{}

//获得按钮的ID
QString CTagButton::getId()
{
	return m_sButtonId;
}

void CTagButton::setIsTagVisible(bool bShowTag)
{
	m_bShowTag = bShowTag;
	update();
}

/**
* @brief paintEvent 绘制事件
* @param event 设置绘制事件对象
*/
void CTagButton::paintEvent(QPaintEvent * event)
{
	QPushButton::paintEvent(event);

	//绘制黄色标记
	if (m_bShowTag) 
	{
		QPainter painter(this);
		painter.setRenderHint(QPainter::Antialiasing, true); // 光滑渲染
		painter.setBrush(Qt::green);
		painter.setPen(Qt::NoPen);
		int radius = 5;
		QPoint center = QPoint(radius + 10, height() / 2);
		painter.drawEllipse(center, radius, radius);
	}
}

void CTagButton::initUI()
{
	//connect(this, &QPushButton::clicked, this, &CTagButton::slotSetTag);
}

void CTagButton::initData()
{
	m_sButtonId = QUuid::createUuid().toString();
	m_bShowTag = false;
}

/**
* @brief slotSetTagVisible 设置标签可见性
* @param
*/
void CTagButton::slotSetTagVisible(QString sButtonId, bool bVisible)
{
	if (sButtonId != m_sButtonId)
	{
		m_bShowTag = false;
	}
	else
	{
		m_bShowTag = bVisible;
	}

	update();
}

/**
* @brief slotSetTag 设置按钮的标签
* @param
*/
void CTagButton::slotSetTag()
{
	//已经显示了标签 隐藏
	if (m_bShowTag)
	{
		m_bShowTag = false;
	}
	//未显示标签 显示
	else
	{
		m_bShowTag = true;
	}

	update();
}
